package xna.android.players;

import xna.android.Utils.SpriteTile;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;

/**
 * Classe que movimenta o personam
 * @author bruno.penha@gmail.com
 *
 */
public class Player extends SpriteTile{
	
	
	private String previousAnimation = "";
	
	public int lifebar =100;
	
	public int moveXBy = 0;
	public int moveYBy = 0;
	public int speed = 10;
	
	private Point moveTo = new Point(10,10);

	public Player(int bitmapResourceId, int xmlAnimationResourceId, Context context){

		super(bitmapResourceId,xmlAnimationResourceId,context);
		this.previousAnimation = this.getCurrentAnimation();
	}

	public void animateTo(Point point)
	{
		moveTo = point;
	}

	public void moveTo(Point point){
		
		moveTo = point;
		this.setXPos(point.x);
		this.setYPos(point.y);
	}
	
	public void updateLocation(){
		/*//TODO utilizar qdo o cenario de Tile estiver pronto...
		if(this.moveXBy != 0){
			this.setxPos( getxPos() + this.moveXBy);
		}
		
		if(this.moveYBy != 0){
			this.setyPos(getyPos() + this.moveYBy);
			
		}*/
		
		if(moveTo.y > this.getYPos()){
			this.setYPos(getYPos() + speed);
		}
		else if(moveTo.y < this.getYPos()){
			this.setYPos(getYPos() - speed);
		}
		
		if(moveTo.x > this.getXPos()){
			this.setXPos(getXPos() + speed);
		}
		else if(moveTo.x < this.getXPos()){
			this.setXPos(getXPos() - speed);
		}
		
		
			
	}
	
	@Override
	public void draw(Canvas canvas) {
		this.updateLocation();
		super.draw(canvas);
	}

	@Override
	public void setCurrentAnimation(String currentAnimation, boolean resetLoop) {
		this.previousAnimation = getCurrentAnimation();
		super.setCurrentAnimation(currentAnimation, resetLoop);
	}

	@Override
	public void setXPos(int xPos) {
		// if(xpos > 32 && xpos < screenWidth - 32)
		super.setXPos(xPos);
	}

	
	
}
